// pages/growth/growth.js
const app = getApp();

Page({

  /**
   * 页面的初始数据
   */
  data: {
    height: "",
    weight: "",
    headcircumference: "",
    navbarData: {
      showCapsule: 1, //是否显示左上角图标   1表示显示    0表示不显示
      title: '体格自评', //导航栏 中间的标题
    },
    navHeight: app.globalData.statusBarHeight * 2 + 116,
    disable:false
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  // bindHeightInput: function (e) {
  //   this.setData({
  //     height: e.detail.value
  //   })
  // },
  // bindWeightInput: function (e) {

  //   this.setData({
  //     weight: e.detail.value
  //   })
  // },
  // bindHeadInput: function (e) {
  //   console.log(e),
  //     this.setData({
  //       headcircumference: e.detail.value
  //     })
  // },
  //处理数据提交的页面
  growthSubmit: function (e) {
    var that=this;
    var height = e.detail.value.height
    var weight = e.detail.value.weight
    var headcircumference = e.detail.value.headcircumference
    if (height == "") {
      wx.showToast({
        title: '身高不能为空',
        icon:'none'
      })
      return false;
    } else if (height <= 0) {
      wx.showToast({
        title: '请输入正确身高',
        icon: 'none'
      })
      return false;
    }
    if (weight == "") {
      wx.showToast({
        title: '体重不能为空',
        icon: 'none'
      })
      return false;
    } else if (weight <= 0) {
      wx.showToast({
        title: '请输入正确体重',
        icon: 'none'
      })
      return false;
    }
    if (headcircumference == "") {
      wx.showToast({
        title: '头围不能为空',
        icon: 'none'
      })
      return false;
    } else if (headcircumference <= 0) {
      wx.showToast({
        title: '请输入正确头围',
        icon: 'none'
      })
      return false;
    }
    wx.showLoading({
      title: "处理中",
      mask: true,
      success() {
        that.setData({
          disable:true
        })
        wx.request({
          url: app.getUrl('/xcx/growth/receive'),
          method: 'GET',
          header: wx.getStorageSync('cookie'),
          data: {
            height: height,
            weight: weight,
            headcircumference: headcircumference
          },
          success(res) {
            if (res.data.code == 0) {
              wx.showToast({
                title: "评测完成",
                icon: 'none',
                duration: 1000
              });
              setTimeout(function () {
                wx.navigateTo({
                  url: '../report/growthReportScheme/growthReportScheme?id=' + res.data.data,
                })
              }, 1000);
            }
          }
        })
      }
    });
  },
  growth_history: function () {
    wx.navigateTo({
      url: '../growth/growthHistoryList/growthHistoryList',
    })
  }
})